package com.stormrage.edu.dao.exam.impl;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.stormrage.edu.dao.exam.ExmAnswerDao;
import com.stormrage.entity.exam.ExmAnswer;
import com.stormragetech.core.dao.MysBaseDao;
import com.stormragetech.core.exception.StormrageTechException;

/**
 * @Title: ExmExamAnswerDaoImpl.java
 * @Package com.stormrage.edu.dao.exam.impl
 * @Description: 考试试题答案 Dao
 * @author www.stormragetech.com
 * @date 2016年4月24日
 * @version V1.0
 */
@Repository
public class ExmAnswerDaoImpl extends MysBaseDao implements ExmAnswerDao {

	private static final Logger logger = LoggerFactory.getLogger(ExmAnswerDaoImpl.class);

	@Override
	public Integer create(final ExmAnswer arg0) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 ExmExamAnswerDao 】-【 Create 】- 开始运行 ");

		final String query = "INSERT INTO exm_answer (answer, exam_id, correct) VALUES"
				+ " (:answer, :examId, :correct)";
		logger.debug(" 数据库执行语句为 " + query);

		Integer index = create(query, arg0);

		logger.debug(" 【 Dao 】-【 ExmExamAnswerDao 】-【 Create 】- 完成运行 ");
		return index;

	}

	@Override
	public void update(final ExmAnswer arg0) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 ExmExamAnswerDao 】-【 update 】- 开始运行 ");

		final String query = "UPDATE exm_answer SET answer = :answer, correct = :correct WHERE id = :id";
		logger.debug(" 数据库执行语句为 " + query);

		update(query, arg0);

		logger.debug(" 【 Dao 】-【 ExmExamAnswerDao 】-【 update 】- 完成运行 ");

	}

	@Override
	public void delete(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 ExmExamAnswerDao 】-【 update 】- 开始运行 ");

		final String query = "DELETE FROM exm_answer WHERE id = :id";
		logger.debug(" 数据库执行语句为 " + query);

		update(query, map);

		logger.debug(" 【 Dao 】-【 ExmExamAnswerDao 】-【 update 】- 完成运行 ");

	}

	@Override
	public Integer queryCountByExamId(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 ExmExamAnswerDao 】-【 queryCountByExamId 】- 开始运行 ");

		final String query = "SELECT COUNT(*) FROM exm_answer WHERE exam_id = :examId";
		logger.debug(" 数据库执行语句为 " + query);

		Integer count = queryCount(query, map);

		logger.debug(" 【 Dao 】-【 ExmExamAnswerDao 】-【 queryCountByExamId 】- 完成运行 ");
		return count;

	}

	@Override
	public ExmAnswer queryById(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 ExmExamAnswerDao 】-【 queryById 】- 开始运行 ");

		final String query = "SELECT * FROM exm_answer WHERE id = :id";
		logger.debug(" 数据库执行语句为 " + query);

		ExmAnswer entity = queryObject(query, ExmAnswer.class, map);

		logger.debug(" 【 Dao 】-【 ExmExamAnswerDao 】-【 queryById 】- 完成运行 ");
		return entity;

	}

	@Override
	public List<ExmAnswer> queryListByExamId(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 ExmExamAnswerDao 】-【 queryListByRelateId 】- 开始运行 ");

		final String query = "SELECT * FROM exm_answer WHERE exam_id = :examId";
		logger.debug(" 数据库执行语句为 " + query);

		List<ExmAnswer> array = queryList(query, ExmAnswer.class, map);

		logger.debug(" 【 Dao 】-【 ExmExamAnswerDao 】-【 queryListByRelateId 】- 完成运行 ");
		return array;

	}

}
